package com.epalmpay.controller.channel.datareport;



import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.epalmpay.commom.BaseController;
import com.epalmpay.exception.ApplicationException;
import com.epalmpay.status.Rescode;
import com.epalmpay.dto.datareport.WalletDataReportInDTO;
import com.epalmpay.dto.datareport.WalletDataReportListOutDTO;
import com.epalmpay.entity.GroupAccountLogDaySum;
import com.epalmpay.entity.GroupAccountLogMonthSum;
import com.epalmpay.entity.StatisAgentDay;
import com.epalmpay.entity.StatisAgentMonth;
import com.epalmpay.entity.StatisMemberDay;
import com.epalmpay.entity.StatisMemberMonth;
import com.epalmpay.entity.StatisShopDay;
import com.epalmpay.entity.StatisShopMonth;
import com.epalmpay.service.datareport.IWalletDataReportService;

/** 
 * 说明：数据报表 :营销数据列表
 * 创建人：gwn
 * 创建时间：2017-06-21
 */

@Controller
@RequestMapping(value="/merchant/walletDataReport")
public class WallerDataReportController  extends BaseController{
	
	@Resource
	private IWalletDataReportService walletDataReportService;

	
	@RequestMapping(value="/list")
	@ResponseBody
	public WalletDataReportListOutDTO list(WalletDataReportInDTO walletDataReportInDTO){
		
		WalletDataReportListOutDTO walletDataReportListOutDTO = new WalletDataReportListOutDTO();
		try {
			
			if (walletDataReportInDTO.getQueryDayOrMonth()==1) {
				if (walletDataReportInDTO.getJoinStart()==null) {
					Date date=new Date();//取时间
					Calendar calendar = new GregorianCalendar();
					calendar.setTime(date);
					calendar.add(calendar.DATE,-1);//把日期往前减少一天，若想把日期向后推一天则将负数改为正数
					date=calendar.getTime();
					walletDataReportInDTO.setJoinStart(date);
				}
				//会员钱包账户余额
				StatisMemberDay statisMemberDay = walletDataReportService.queryMemberAmount(walletDataReportInDTO);
				walletDataReportListOutDTO.setStatisMemberDay(statisMemberDay);
				//商户钱包账户余额
				StatisShopDay statisShopDay = walletDataReportService.qyeryShopDayAmount(walletDataReportInDTO);
				walletDataReportListOutDTO.setStatisShopDay(statisShopDay);
				//代理商账户余额
				StatisAgentDay statisAgentDay =walletDataReportService.qyeryAgentDayAmount(walletDataReportInDTO);
				walletDataReportListOutDTO.setStatisAgentDay(statisAgentDay);
				//营销账户余额
				GroupAccountLogDaySum groupAccountLogDaySum = walletDataReportService.queryGroupAccountDay(walletDataReportInDTO);
				walletDataReportListOutDTO.setGroupAccountLogDaySum(groupAccountLogDaySum);
				
			}
			
			//查询月的
			if (walletDataReportInDTO.getQueryDayOrMonth()!=1) {
				//会员钱包账户余额
			    StatisMemberMonth statisMemberMonth = walletDataReportService.queryMemberMonthAmount(walletDataReportInDTO);
				walletDataReportListOutDTO.setStatisMemberMonth(statisMemberMonth);
				//商户钱包账户余额
				StatisShopMonth statisShopMonth = walletDataReportService.qyeryShopMonthAmount(walletDataReportInDTO);
				walletDataReportListOutDTO.setStatisShopMonth(statisShopMonth);
				//代理商账户余额
				StatisAgentMonth statisAgentMonth =walletDataReportService.qyeryAgentMonthAmount(walletDataReportInDTO);
				walletDataReportListOutDTO.setStatisAgentMonth(statisAgentMonth);
				//营销 账户余额
				GroupAccountLogMonthSum groupAccountLogMonthSum = walletDataReportService.queryGroupAccountMonth(walletDataReportInDTO);
				walletDataReportListOutDTO.setGroupAccountLogMonthSum(groupAccountLogMonthSum);
		
				
				
			}
			
			
			walletDataReportListOutDTO.setErrorCode(Rescode.SUCCESS, "处理成功");
			return walletDataReportListOutDTO;
		} catch (ApplicationException ae) { 
			walletDataReportListOutDTO.setErrorCode(ae.errCode, ae.errMsg);
			ae.printStackTrace();
		}catch (Exception e) {
			walletDataReportListOutDTO.setErrorCode(Rescode.DEFAULT_PREFIX, "处理出现异常");
				e.printStackTrace();
		}
		return walletDataReportListOutDTO;
		
	}
	
	
}
